//
//  ViewController.m
//  2016-06-08 Homework TomCat
//
//  Created by Roach on 16/6/8.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "ClownButton.h"
#import "drinkButton.h"
#import "eatButton.h"
#import "fartButton.h"
#import "pieButton.h"
#import "scratchButton.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatImageView];
    [self creatButton];
    // Do any additional setup after loading the view, typically from a nib.
}

// 背景
- (void) creatImageView {
    
    UIImage *backgroundView = [UIImage imageNamed:@"angry_00.jpg"];
    UIImageView *backgroundImageView = [[UIImageView alloc]initWithImage:backgroundView];
    backgroundImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview: backgroundImageView];
    [backgroundImageView release];
    
}

// 按钮
- (void) creatButton {
    
    ClownButton *cymbal = [ClownButton button];
    cymbal.frame = CGRectMake(10, 370, 50, 50);
    [self.view addSubview:cymbal];
    [cymbal release];
    
    [cymbal addTarget:self action:@selector(addCymbalImage:) forControlEvents:UIControlEventTouchUpInside];
    [self.view bringSubviewToFront:cymbal];
    

    drinkButton *drink = [drinkButton button];
    drink.frame = CGRectMake(10, 430, 50, 50);
    [self.view addSubview:drink];
    [drink release];
    
    [drink addTarget:self action:@selector(addDrinkImage:) forControlEvents:UIControlEventTouchUpInside];
    
    eatButton *eat = [eatButton button];
    eat.frame = CGRectMake(10, 490, 50, 50);
    [self.view addSubview:eat];
    [eat release];
    [eat addTarget:self action:@selector(addEatImage:) forControlEvents:UIControlEventTouchUpInside];
    
    fartButton *fart = [fartButton button];
    fart.frame = CGRectMake(300, 370, 50, 50);
    [self.view addSubview:fart];
    [fart release];
    
    [fart addTarget:self action:@selector(addFartImage:) forControlEvents:UIControlEventTouchUpInside];
    
    pieButton *pie = [pieButton button];
    pie.frame = CGRectMake(300, 430, 50, 50);
    [self.view addSubview:pie];
    [pie release];
    [pie addTarget:self action:@selector(addPieImage:) forControlEvents:UIControlEventTouchUpInside];
    
    scratchButton *scratch = [scratchButton button];
    scratch.frame = CGRectMake(300, 490, 50, 50);
    [self.view addSubview:scratch];
    [scratch release];
    [scratch addTarget:self action:@selector(addScratchImage:) forControlEvents:UIControlEventTouchUpInside];

    
    
}


- (void)addCymbalImage:(ClownButton *)button {
    UIImageView *cymbalImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cymbal_00.jpg"]];
    cymbalImage.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:cymbalImage];
    [cymbalImage release];
    
    
    NSMutableArray *muarray = [NSMutableArray arrayWithCapacity:13];
    
    for (int i = 0; i <= 12; i ++) {
        
        NSString *name = [NSString stringWithFormat:@"cymbal_%.2d.jpg", i];
        UIImage *animationImage = [UIImage imageNamed:name];
        
        [muarray addObject:animationImage];
    }
    
    cymbalImage.animationImages = muarray;
    cymbalImage.animationDuration = 2;
    cymbalImage.animationRepeatCount = 1;
    [cymbalImage startAnimating];
    [self.view bringSubviewToFront:cymbalImage];
    
    
}

- (void)addDrinkImage:(drinkButton *)button {
    
    UIImageView *drinkImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"drink_00.jpg"]];
    drinkImage.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:drinkImage];
    [drinkImage release];
    
    
    NSMutableArray *muarray = [NSMutableArray arrayWithCapacity:81];
    
    for (int i = 0; i <= 80; i ++) {
        
        NSString *name = [NSString stringWithFormat:@"drink_%.2d.jpg", i];
        UIImage *animationImage = [UIImage imageNamed:name];
        
        [muarray addObject:animationImage];
    }
    
    drinkImage.animationImages = muarray;
    drinkImage.animationDuration = 5;
    drinkImage.animationRepeatCount = 1;
    [drinkImage startAnimating];

    
    
}

- (void)addEatImage:(eatButton *)button {
    UIImageView *eatImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"eat_00.jpg"]];
    eatImage.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:eatImage];
    [eatImage release];
    
    
    NSMutableArray *muarray = [NSMutableArray arrayWithCapacity:40];
    
    for (int i = 0; i <= 39; i ++) {
        
        NSString *name = [NSString stringWithFormat:@"eat_%.2d.jpg", i];
        UIImage *animationImage = [UIImage imageNamed:name];
        
        [muarray addObject:animationImage];
    }
    
    eatImage.animationImages = muarray;
    eatImage.animationDuration = 3;
    eatImage.animationRepeatCount = 1;
    [eatImage startAnimating];
}

- (void)addFartImage:(fartButton *) button {
    UIImageView *fartImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fart_00.jpg"]];
    fartImage.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:fartImage];
    [fartImage release];
    
    
    NSMutableArray *muarray = [NSMutableArray arrayWithCapacity:28];
    
    for (int i = 0; i <= 27; i ++) {
        
        NSString *name = [NSString stringWithFormat:@"fart_%.2d.jpg", i];
        UIImage *animationImage = [UIImage imageNamed:name];
        
        [muarray addObject:animationImage];
    }
    
    fartImage.animationImages = muarray;
    fartImage.animationDuration = 3;
    fartImage.animationRepeatCount = 1;
    [fartImage startAnimating];
}

- (void)addPieImage:(pieButton *)button{
    UIImageView *pieImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pie_00.jpg"]];
    pieImage.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:pieImage];
    [pieImage release];
    
    
    NSMutableArray *muarray = [NSMutableArray arrayWithCapacity:81];
    
    for (int i = 0; i <= 23; i ++) {
        
        NSString *name = [NSString stringWithFormat:@"pie_%.2d.jpg", i];
        UIImage *animationImage = [UIImage imageNamed:name];
        
        [muarray addObject:animationImage];
    }
    
    pieImage.animationImages = muarray;
    pieImage.animationDuration = 3;
    pieImage.animationRepeatCount = 1;
    [pieImage startAnimating];
}

- (void)addScratchImage:(scratchButton *)button{
    UIImageView *scratchImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scratch_00.jpg"]];
    scratchImage.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:scratchImage];
    [scratchImage release];
    
    
    NSMutableArray *muarray = [NSMutableArray arrayWithCapacity:56];
    
    for (int i = 0; i <= 55; i ++) {
        
        NSString *name = [NSString stringWithFormat:@"scratch_%.2d.jpg", i];
        UIImage *animationImage = [UIImage imageNamed:name];
        
        [muarray addObject:animationImage];
    }
    
    scratchImage.animationImages = muarray;
    scratchImage.animationDuration = 4;
    scratchImage.animationRepeatCount = 1;
    [scratchImage startAnimating];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
